package demo1;

import java.util.ArrayList;
import java.util.List;

public class StudentManager {
    //创建集合
    private static List<Student>students=new ArrayList<>();
    //集合元素初始化
    static {
          Student student1=new Student("202001","小高",18);
          Student student2=new Student("202002","小黄",18);
          students.add(student1);
          students.add(student2);
    }
    //增加学员
    public static boolean adds(Student student){
        Student temp=null;
        boolean flag=false;
        for (int i = 0; i <students.size(); i++) {
            temp=students.get(i);
            if (temp!=null&&temp.getId().equals(student.getId())){
            flag=true;
            break;
            }
        }
        if (!flag){
            students.add(student);
            return true;
        }
        else {
            return false;
        }
    }
    //显示所有学员信息
    public static List<Student>findAll(){
        return students;
    }
    //删除学员
    public static boolean deleteSong(String name){
        boolean flag=false;
        for (int i = 0; i <students.size() ; i++) {
            if (students.get(i)!=null&&name.equals(students.get(i).getName())){
                students.remove(i);
                flag=true;
                break;
            }
        }
        if (!flag){
            return false;
        }
        else {
            return true;
        }
    }
    public static boolean mod(Student student){
        int index=-1;
        for (int i = 0; i <students.size() ; i++) {
            if (students.get(i).getName().equals(student.getName())){
                index=i;
                break;
            }
        }
        if (index!=-1){
            students.set(index,student);
            return true;
        }
        else {
            return false;
        }

    }
}
